package util

import "strconv"

//go:generate genny -in=cast_template.go -out=gen_cast.go gen "ValueOneType=int" "ValueTwoType=int"

// StringToIntSlice converts []string to []int
func StringToIntSlice(from []string) ([]int, error) {
	var err error
	to := make([]int, len(from))
	for i, val := range from {
		to[i], err = strconv.Atoi(val)
		if err != nil {
			return nil, err
		}
	}
	return to, nil
}

// IntToStringSlice converts []int to []string
func IntToStringSlice(from []int) []string {
	to := make([]string, len(from))
	for i, val := range from {
		to[i] = strconv.Itoa(val)
	}
	return to
}

// StringToInt converts string to int
func StringToInt(from string) (to int, err error) {
	to, err = strconv.Atoi(from)
	return to, err
}

// IntToString converts int to string
func IntToString(from int) (to string) {
	to = strconv.Itoa(from)
	return to
}
